
#include "test_list_int_tiling.h"
#include "register/op_def_registry.h"


namespace optiling {
static ge::graphStatus TilingFunc(gert::TilingContext* context)
{

    TestListIntTilingData tiling;
    const gert::StorageShape* x1_shape = context->GetInputShape(0);
    int32_t data_sz = 1;
    for (int i = 0; i < x1_shape->GetStorageShape().GetDimNum(); i++)
        data_sz *= x1_shape->GetStorageShape().GetDim(i);
    tiling.set_size(data_sz);
    context->SetBlockDim(8);

    // auto *prtol = context->GetAttrs()->GetFloat(0);
    // float rtol =  *prtol;
    // std::cout << "rtol:" << rtol << std::endl;

    auto *pqseqlencv = context->GetAttrs()->GetListInt(0);
    const int64_t *pqseqlen = pqseqlencv->GetData();
    int32_t qseqlen_size = pqseqlencv->GetSize();
    
    std::cout << "qseqlen_size:" << qseqlen_size << std::endl;
    std::cout << "pqseqlen:" << *pqseqlen << std::endl;
    if(pqseqlencv == nullptr) {
        std::cout << "null ptr:" << std::endl;
    }

    tiling.SaveToBuffer(context->GetRawTilingData()->GetData(), context->GetRawTilingData()->GetCapacity());
    context->GetRawTilingData()->SetDataSize(tiling.GetDataSize());

    return ge::GRAPH_SUCCESS;
}
}


namespace ge {
static ge::graphStatus InferShape(gert::InferShapeContext* context)
{
    const gert::Shape* x1_shape = context->GetInputShape(0);
    gert::Shape* y_shape = context->GetOutputShape(0);
    *y_shape = *x1_shape;
    return GRAPH_SUCCESS;
}
}


namespace ops {
class TestListInt : public OpDef {
public:
    explicit TestListInt(const char* name) : OpDef(name)
    {
        this->Input("x1")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT16})
            .Format({ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND});
        this->Input("x2")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT16})
            .Format({ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND});
        this->Output("y")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT16})
            .Format({ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND});  
        this->Attr("qseqlen").AttrType(OPTIONAL).ListInt();

        this->SetInferShape(ge::InferShape);

        this->AICore()
            .SetTiling(optiling::TilingFunc);
        this->AICore().AddConfig("ascend310b");

    }
};

OP_ADD(TestListInt);
}
